package com.hd.auto;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.ecf.cfis.facade.biz.mtp.MtpFacade;
import com.ecf.cfis.facade.request.mtp.QueryProdDetailReq;
import com.ecf.cfis.facade.response.mtp.QueryProdDetailResp;
import com.ecf.ofc.facade.LoanApplicationFacade;
import com.ecf.ofc.facade.LoanPlanFacade;
import com.ecf.ofc.facade.LoanSignFacade;
import com.ecf.ofc.facade.MaterialEntryImgFacade;
import com.ecf.ofc.facade.PreEvaluationImgFacade;
import com.ecf.ofc.facade.dto.LoanApplicationBean;
import com.ecf.ofc.facade.dto.MaterialEntryBean;
import com.ecf.ofc.facade.dto.PreEvaluationImgBean;
import com.ecf.ofc.facade.request.ConfirmLoanSignRequest;
import com.ecf.ofc.facade.request.CreateLoanApplicationRequest;
import com.ecf.ofc.facade.request.CreateMaterialEntryImgRequest;
import com.ecf.ofc.facade.request.CreatePreEvaluationImgRequest;
import com.ecf.ofc.facade.request.QueryLoanSignRequest;
import com.ecf.ofc.facade.request.UpdateLoanApplicationRequest;
import com.ecf.ofc.facade.request.UpdateLoanPlanExtRequest;
import com.ecf.ofc.facade.response.ConfirmLoanSignResponse;
import com.ecf.ofc.facade.response.CreateLoanApplicationResponse;
import com.ecf.ofc.facade.response.CreateMaterialEntryImgResponse;
import com.ecf.ofc.facade.response.CreatePreEvaluationImgResponse;
import com.ecf.ofc.facade.response.QueryLoanSignResponse;
import com.ecf.ofc.facade.response.UpdateLoanPlanResponse;
import com.ecf.ucenter.facade.UCenterUserFacade;
import com.ecf.ucenter.facade.bean.UserExtendBean;
import com.ecf.ucenter.facade.request.user.QueryUserInfoRequest;
import com.ecf.ucenter.facade.request.user.RegisterUserInfoRequest;
import com.ecf.ucenter.facade.response.user.QueryUserInfoResponse;
import com.ecf.ucenter.facade.response.user.RegisterUserInfoResponse;
import com.hd.until.CommonToolUtil;
import com.hd.until.DBUtil;
import com.hd.until.HttplTestUti;
import com.hd.until.IdGeneratorService;
import com.hd.until.TestEif;

import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.testng.xml.Parser;

//@RunWith(SpringJUnit4ClassRunner.class)
@Test
@ContextConfiguration("classpath:spring-test.xml")
public class CopyOfLoanReqToOFCTest extends AbstractTestNGSpringContextTests {

	Map<String, String> map = new HashMap<String, String>();
	
	Logger logger  =  Logger.getLogger("log4j.properties");



	@Reference
	PreEvaluationImgFacade preEvaluationImgFacade;

	@Reference
	LoanPlanFacade loanPlanFacade;

	@Reference
	MaterialEntryImgFacade materialEntryImgFacade;

	@Reference
	LoanApplicationFacade loanApplicationFacade;

	@Reference
	LoanSignFacade loanSignFacade;
	
	@Reference
	MtpFacade cfisMtpFacade;
	
	@Reference
	UCenterUserFacade uCenterUserFacade;
	

	/*
	 * 基础参数初始化
	 */
	@BeforeClass
	public void initMap(){

//		---------------------银行卡信息---------------------------------------------------
		map.put("bankCardNo", CommonToolUtil.getCMBCardNo());
		map.put("bankName", "招商银行");
		map.put("bankNo", "03080000");
			
		map.put("trackingNo",IdGeneratorService.generator20ID());		
//		map.put("loanApplySerialNo", IdGeneratorService.generator17ID());
//		map.put("loanApplicationNo", IdGeneratorService.generator20ID());
		//其他信息
		map.put("baseMaterial","{\"censusRegisterFirstAdminDiv\":{\"areaCode\":\"110000\",\"areaName\":\"北京市\",\"sortNo\":\"11\"},\"censusRegisterSecondAdminDiv\":{\"areaCode\":\"110100\",\"areaName\":\"北京市市辖区\",\"sortNo\":\"1101\"},\"censusRegisterThridAdminDiv\":{\"areaCode\":\"110101\",\"areaName\":\"北京市市辖区东城区\",\"sortNo\":\"110101\"},\"childrenCount\":\"NO_CHILDREN\",\"eduExperienceType\":\"MDPOSTGRADUATE\",\"email\":\"gsgsg@hotmail.com\",\"familyAddress\":\"广东省东莞市百悦尚城1553号1079单元867\",\"familyAddressFirstAdminDiv\":{\"areaCode\":\"440000\",\"areaName\":\"广东省\",\"sortNo\":\"44\"},\"familyAddressSecondAdminDiv\":{\"areaCode\":\"441900\",\"areaName\":\"广东省东莞市\",\"sortNo\":\"4419\"},\"familyAddressThridAdminDiv\":{\"areaCode\":\"441900\",\"areaName\":\"广东省东莞市\",\"sortNo\":\"4419\"},\"familyBuildingNo\":\"1553号\",\"familyDistrict\":\"百悦尚城\",\"familyHouseNo\":\"867\",\"familyUnitNo\":\"1079单元\",\"isFinished\":1,\"isNeedUpdate\":0,\"marriage\":\"UNMARRIED\",\"mobilePhone\":\"18900000881\",\"type\":\"MD_BASE\"}");
		map.put("spouseAndContacts","{\"firstContactName\":\"牛肉\",\"firstContactPhone\":\"13666669999\",\"firstContactRelation\":\"MDFATHER\",\"isFinished\":1,\"marriageStatus\":\"UNMARRIED\",\"secondContactName\":\"牛肉粒\",\"secondContactPhone\":\"13655558848\",\"secondContactRelation\":\"MDRELATIVE\",\"type\":\"MD_CONTACT\"}");
		map.put("incomeAndAssets","{\"companyName\":\"进入你的\",\"companyPhone\":\"0101-33646799\",\"isFinished\":1,\"salary\":\"30000\",\"type\":\"MD_WORK\",\"workAddressFirstAdminDiv\":{\"areaCode\":\"110000\",\"areaName\":\"北京市\",\"sortNo\":\"11\"},\"workAddressSecondAdminDiv\":{\"areaCode\":\"110100\",\"areaName\":\"北京市市辖区\",\"sortNo\":\"1101\"},\"workAddressThridAdminDiv\":{\"areaCode\":\"110101\",\"areaName\":\"北京市市辖区东城区\",\"sortNo\":\"110101\"}}");
		map.put("bankCard","{\"bankCardNo\":\"6214856544256880\",\"bankName\":\"招商银行\",\"bankNo\":\"03080000\",\"bindMobilePhone\":\"18900000881\",\"isFinished\":1,\"type\":\"BANK_CARD\"}");			
		map.put("financialSource","{\"routerChannel\":0,\"routerChannelName\":\"恒大小贷\",\"routerDate\":1516000536967}");
		map.put("certiPicPathFront","http://qfdfs.hengdadai.com/group1/M00/00/23/rBA0HVm48r6Ad7mVAAGOYtV_Ezc949.jpg");
		map.put("certiPicPathBack","http://qfdfs.hengdadai.com/group1/M00/00/23/rBA0HVm48r6Ad7mVAAGOYtV_Ezc949.jpg");
		map.put("certiPicPathPerson","http://qfdfs.hengdadai.com/group1/M00/00/23/rBA0HVm48r6Ad7mVAAGOYtV_Ezc949.jpg");
		map.put("certiPicPathBackNarrow","http://qfdfs.hengdadai.com/group1/M00/00/23/rBA0HVm48r6Ad7mVAAGOYtV_Ezc949.jpg");
		map.put("certiPicPathPersonNarrow","http://qfdfs.hengdadai.com/group1/M00/00/23/rBA0HVm48r6Ad7mVAAGOYtV_Ezc949.jpg");
		map.put("certiPicPathFrontNarrow","http://qfdfs.hengdadai.com/group1/M00/00/23/rBA0HVm48r6Ad7mVAAGOYtV_Ezc949.jpg");
		map.put("supplementInfo","{\"fundDepositMonth\":\"\",\"mortgagePaymentMonth\":\"\",\"socialSecurityDepositMonth\":\"\",\"type\":\"DE_SUPPLEMENTARY\"}");
		map.put("addressInfoBigData","{\"propertyCity\":\"佛山市\",\"propertyCityDistrict\":\"清远市阳山县\",\"propertyCityDistrictNo\":\"441823\",\"propertyCityNo\":\"441800\",\"propertyDistrict\":\"恒大御景半岛\",\"propertyFloor\":\"1218号\",\"propertyProvince\":\"广东省\",\"propertyProvinceNo\":\"440000\",\"propertyRoom\":\"1411\",\"propertyUnit\":\"192单元\"}");			
		
	}
	
	/*
	 * 公共信息初始化
	 */
	public void initCommonMap(){
		map.put("bankCardNo", CommonToolUtil.getCMBCardNo());
		map.put("bankName", "招商银行");
		map.put("bankNo", "03080000");
	}
	
	@Test(enabled=false)
	public void initJSDMap(){
		String sql = "SELECT * FROM ecf_ucenter.`t_ucenter_property_owner` t2 WHERE t2.`jsd_status`='1' AND t2.`jsd_marketing_flag`='1' AND user_uuid = '' LIMIT 1";
		String str = DBUtil.mySQLUtilForQuery(sql);
		if(!"".equals(str) && str != null){
			String coustom[] = str.split(",");
			//个人信息
			map.put("memberName",coustom[3]);
//			map.put("memberNo",coustom[2]);
			map.put("mermberPhone", coustom[8]);
			map.put("certId", coustom[7]);
			//产品信息
			map.put("productId","35");
			map.put("productType","0");
			map.put("repaymentType","RPT-01");
			map.put("termMonth","3");
			map.put("loanSum", "30000");
			map.put("specific_Id","YZDJS0001");
			map.put("realEstateInfo","2422");
			map.put("feeRate", "0");
			map.put("cutRate", "0");
		}else{
			Assert.assertTrue(false, "获取大数据为空....");
		}
		
	}
	
	@Test(enabled=false)
	public void initMDMap(){
		String sql = "SELECT * FROM ecf_ucenter.`t_ucenter_property_owner` t2 WHERE t2.`jsd_status`='1' AND t2.`jsd_marketing_flag`='1' AND user_uuid = '' LIMIT 1";
		String str = DBUtil.mySQLUtilForQuery(sql);
		if(!"".equals(str) && str != null){
			String coustom[] = str.split(",");
			//个人信息
			map.put("memberName",coustom[3]);
//			map.put("memberNo",coustom[2]);
			map.put("mermberPhone", coustom[8]);
			map.put("certId", coustom[7]);
			//产品信息
			map.put("productId","35");
			map.put("productType","0");
			map.put("repaymentType","RPT-01");
			map.put("termMonth","3");
			map.put("loanSum", "30000");
			map.put("specific_Id","YZDJS0001");
			map.put("realEstateInfo","2422");
			map.put("feeRate", "0");
			map.put("cutRate", "0");
		}else{
			Assert.assertTrue(false, "获取大数据为空....");
		}
		
	}
	
	
	@Test(enabled=false)
	public void initMemberNo(String phoneNo){
		String sql = "SELECT * FROM ecf_ucenter.`t_ucenter_property_owner` t2 WHERE t2.mobile = '"+ phoneNo + "' LIMIT 1";
		String str = DBUtil.mySQLUtilForQuery(sql);
		if(!"".equals(str) && str != null){
			String coustom[] = str.split(",");
			map.put("memberNo",coustom[2]);
		}
		else{
			Assert.assertTrue(false, "初始化memberno失败....");
		}
	}
	
	/*
	 * ucenter注册接口，调用此接口后 可以通过APP端登陆查看
	 */
	/*
	public void registerToUcenter(){
		QueryUserInfoRequest user = new QueryUserInfoRequest();	
		user.setUnimId("");
		QueryUserInfoResponse  getuser = uCenterUserFacade.queryUserInfo(user);
		RegisterUserInfoRequest request = new RegisterUserInfoRequest();
		request.setBindPhone(bindPhone);
		request.setRealName(realName);
		request.setUserCertification(userCertification);
		UserExtendBean userExtend = new UserExtendBean();
		request.setUserExtend(userExtend);
		RegisterUserInfoResponse response = uCenterUserFacade.registerUserInfo(request);
		response.getUuid();
	}
	 */
	
	/*
	 * 获取进件类别,加载对应产品的初始信息
	 * 
	 */
	@Parameters({"loanProductType"})
	@BeforeClass(dependsOnMethods = {"initMap"})
	public void getLoanPlanType(String loanProductType){
		
		System.out.println("loanProductType====" + loanProductType);
		map.put("loanType", loanProductType);
		if("JSD".equals(loanProductType)){
			System.out.println("开始加载家私贷进件数据...");
			//获取大数据参数
			System.out.println("开始初始化大数据...");
			initJSDMap();
			
		}else if("MD".equals(loanProductType)){
			System.out.println("开始加载秒贷进件数据...");
			initMDMap();
			map.put("productId","29");
			map.put("productType","0");
			map.put("repaymentType","RPT-01");
			map.put("termMonth","3");
			map.put("loanSum", "30000");
			map.put("specific_Id","YZDMD00001");
			map.put("realEstateInfo","2422");
			map.put("feeRate", "0");
			map.put("cutRate", "0");
			
		}else{
			System.out.println("开始加载大额业主贷数据...");
		}
		
		//注册金服并完成实名认证
		System.out.println("开始金服注册和实名...");
		TestEif eif = new TestEif();
		System.out.println("手机号码====:" + map.get("mermberPhone"));
		System.out.println("姓名====:" + map.get("memberName"));
		 eif.registerEif(map.get("mermberPhone"));//
		 eif.loginEif(map.get("mermberPhone"));
		 eif.realNameTOEif(map.get("memberName"), map.get("certId"));
		//根据金服accesscode获取nextToken并注册ECF
		 System.out.println("开始调用ECF注册...");
		 String token = eif.getNextToken();;//获取登陆金服的token
		 String accesscode = eif.getAuthPage(token);//根据token获取到accesscode
		 String nextToken = eif.getNextTokenByAccessCode(accesscode);//根据accesscode获取nextToken
		 eif.registerToECF(nextToken);//根据nextToken调用MTP接口 完成注册
		 //注册完成后，初始化会员信息
		 initMemberNo(map.get("mermberPhone"));
	}
	
	/*
	 * 获取产品编码
	 */

	@BeforeClass(dependsOnMethods = {"getLoanPlanType"})
	public void getSpecificserialNo(){
		 QueryProdDetailReq req = new QueryProdDetailReq();
	        req.setProductId(Long.parseLong(map.get("productId")));
	        req.setProductType(Integer.parseInt(map.get("productType")));
	        req.setBlackWhiteListGroupIds(new ArrayList<String>());
	        QueryProdDetailResp resp = cfisMtpFacade.queryProdDetail(req);
	        map.put("specificserialno", resp.getSerialNo());
	}
	
	/*
	 * 调用预评估接口，获取loanPlanNO
	 */
	@Test
	public void getLoanPlanNO() {
		CreatePreEvaluationImgRequest param = new CreatePreEvaluationImgRequest();
		param.setMicroCreditCompId("");
		PreEvaluationImgBean preBean = new PreEvaluationImgBean();
		preBean.setExpireTime(getDate(7));
		preBean.setMaxAmount(new BigDecimal(30000));
		preBean.setMinAmount(new BigDecimal(30000));
		logger.info("memberNo======" + map.get("memberNo"));
		preBean.setMemberNo(map.get("memberNo"));
		preBean.setProductId(Long.parseLong(map.get("productId")));
		preBean.setProductType(Integer.parseInt(map.get("productType")));
		Byte[] b = { 1 };
		preBean.setStatus(b[0]);
		preBean.setSpecificId(map.get("specific_Id"));
		// preBean.setStatusReason("yuchuangjian");
		param.setPreEvaluationImgBean(preBean);
		param.setTrackingNo(map.get("trackingNo"));
		CreatePreEvaluationImgResponse response = preEvaluationImgFacade
				.createPreEvaluation(param);

		map.put("loanPlanNo", response.getLoanPlanNo());
//		this.setLoanNo(response.getLoanPlanNo());
	}

	/*
	 * 9.进件信息创建（写） 功能说明：用户进件提交审核时调用该表，生成进件表，里面包含用户前端录入信息，银行卡信息，资金路由信息 单据状态扭转为2-1
	 * materialEntryImgFacade.createMaterialEntryImg
	 */
	@Test(dependsOnMethods = { "getLoanPlanNO" })
	public void createMaterialEntryImgTest() {
		CreateMaterialEntryImgRequest request = new CreateMaterialEntryImgRequest();
		request.setLoanPlanNo(map.get("loanPlanNo"));
		request.setTrackingNo(map.get("trackingNo"));
		MaterialEntryBean entry = new MaterialEntryBean();
		entry.setAddressInfoBigData(map.get("addressInfoBigData"));
		entry.setBankCard(map.get("bankCard"));
		entry.setBaseMaterial(map.get("baseMaterial"));
		entry.setCertiPicPathFront(map.get("certiPicPathFront"));
		entry.setBindPhone(map.get("mermberPhone"));
		entry.setCertificateNumber(map.get("certId"));
		entry.setCertificateType(0);
		entry.setCertiPicPathBack(map.get("certiPicPathBack"));
		entry.setCertiPicPathBackNarrow(map.get("certiPicPathBackNarrow"));
		entry.setCertiPicPathFront(map.get("certiPicPathFront"));
		entry.setCertiPicPathPerson(map.get("certiPicPathPerson"));
		entry.setCertiPicPathPersonNarrow(map.get("certiPicPathPersonNarrow"));
		// entry.setContactWay("ddd");
		entry.setCreateTime(new Date());
		// entry.setCreditInquiry("eeee");
		// entry.setCreditPictureInfo("gggg");
		// entry.setEducationAndOccupation("hhh");
		entry.setFinancialSource(map.get("financialSource"));
		entry.setIncomeAndAssets(map.get("incomeAndAssets"));
		logger.info("memberName=========" + map.get("memberName"));
		entry.setMemberName(map.get("memberName"));
		entry.setMemberNo(map.get("memberNo"));
		entry.setProductId(Long.parseLong(map.get("productId")));
		entry.setProductName("家私贷");//
		entry.setProductType(Integer.parseInt(map.get("productType")));
		entry.setPurposeType("FURNITURESHOPPING");// 家私贷：furnitureshopping
		entry.setPurposeType("TRAVEL");//其他贷款 旅游
		entry.setRealEstateInfo(map.get("realEstateInfo"));
		// entry.setSignInfo("oooo");
		entry.setSpecificId(map.get("specific_Id"));
		entry.setSpouseAndContacts(map.get("spouseAndContacts"));
		// entry.setSupplementInfo(this.supplementInfo);
		entry.setCertiPicPathFrontNarrow(map.get("certiPicPathFrontNarrow"));

		request.setMaterialEntryBean(entry);
		CreateMaterialEntryImgResponse response = materialEntryImgFacade
				.createMaterialEntryImg(request);
		if (!response.isSuccess()) {
			System.err.println(response.getMsg());
			System.err.println("调用进件接口失败....");
		} else {
			System.err.println(response.getMsg());
		}
	}

	/*
	 * 11.申请表创建接口（写） 功能说明：用户点击进件提交审核，调用生成申请单，返回申请单号，用于作为唯一流水号 与core交互 单据状态扭转为3-0
	 * loanApplicationFacade.createLoanApplication
	 * 
	 * 获取loan_application_no
	 */
	@Test(dependsOnMethods = { "createMaterialEntryImgTest" })
	public void createLoanApplicationTest() {

		CreateLoanApplicationRequest request = new CreateLoanApplicationRequest();
		request.setLoanPlanNo(map.get("loanPlanNo"));
		request.setTrackingNo(map.get("trackingNo"));
		LoanApplicationBean entry = new LoanApplicationBean();
		entry.setAnnualRate(new BigDecimal(0.16));
		Byte b[] = { 1 };
		entry.setApplyStatus(b[0]);
		entry.setApplyStatusReason("");
		entry.setBidFeeRate(new BigDecimal(0));
//		entry.setBizLoanApplySerialNo(map.get("loanApplySerialNo"));
		entry.setBizLoanApplySerialNo("");
		entry.setCreateTime(new Date());
//		entry.setLoanApplicationNo(map.get("loanApplicationNo"));
//		entry.setLoanPlanNo(map.get("loanPlanNo"));
		entry.setMemberNo(map.get("memberNo"));
		entry.setMonthFeeRate(new BigDecimal(0));
		entry.setPlanLoanAmount(new BigDecimal(30000));
		entry.setProductId(Long.parseLong(map.get("productId")));
		entry.setProductType(Integer.parseInt(map.get("productType")));
		entry.setRepaymentType(map.get("repaymentType"));
		entry.setSpecificId(map.get("specific_Id"));
		entry.setStatusChangeTime(new Date());
		entry.setTermMonth(Integer.parseInt(map.get("termMonth")));
//		entry.setTrackingNo(map.get("trackingNo"));

		request.setLoanApplicationBean(entry);
		CreateLoanApplicationResponse resopnse = loanApplicationFacade
				.createLoanApplication(request);
		
		map.put("loanApplicatinNo", resopnse.getLoanApplicationNo());
	}

	/*
	 * 创建签名信息,由安硕系统调用
	 * LoanSignController.createLoanSign
	 */
	@Test
	public void createLoanSignTest(){
		
	}
	
	/*
	 * 发送进件申请到安硕系统
	 */
	@Test(dependsOnMethods = {"createLoanApplicationTest"})
	public void sentLoanReqToAnShuoTest(){
		//用户加入风控白名单
		String sql = String.format("insert into u_ecf.customer_whitelist values ('%s',1,'%s','','','','',1)", map.get("certId"),map.get("memberName"));
		if(DBUtil.oracleUtilForUpdate(sql)){
			LoanReqToAnShuoTest anshuo = new LoanReqToAnShuoTest(map);
			String resp = anshuo.sendReqToAnShuoTest();
			if("" != resp && resp!= null){
				JSONObject json = JSONObject.fromObject(resp); 
				String res_code = json.getJSONObject("Transaction").getJSONObject("TransHeader").getString("res_code");
				if(res_code.equals("0000")){
					System.out.println("提交审核成功....");
					map.put("applyno", json.getJSONObject("Transaction").getJSONObject("TransBody").getString("applyno"));
					map.put("appserialno", json.getJSONObject("Transaction").getJSONObject("TransBody").getString("appserialno"));
				}else{
					Assert.assertTrue(false, "进件申请失败,安硕返回失败");
				}
			}
			
		}else{
			Assert.assertTrue(false, "更新白名单失败,进件流程终止");
		}
		
		
	}
	
	
	
	/*
	 * 审批通过,调用更新贷款状态接口 LoanApplicationFacade.UpdateLoanApplication
	 */
	@Test(dependsOnMethods = {"sentLoanReqToAnShuoTest"})
	public void updateLoanApplicationTest() throws InterruptedException{
		Thread.sleep(5000);
		UpdateLoanApplicationRequest request = new UpdateLoanApplicationRequest();
		byte[] a = {1};
		request.setApplyStatus(a[0]);
		request.setApplyStatusReason("交易成功");
		request.setBizLoanApplySerialNo(map.get("applyno"));
		request.setLoanApplicationNo(map.get("appserialno"));
		loanApplicationFacade.updateLoanApplication(request);
	}
	
	
	/*
	 * 开始签约流程，签约MTP只跟OFC交互
	 * 1、查询签名id  loanSignFacade.queryLoanSign
	 * 2、提交签名信息  loanSignFacade.confirmLoanSign
	 */
	@Test(dependsOnMethods = {"updateLoanApplicationTest"})
	public void loanSignTest(){

		//查询签约单号
		QueryLoanSignRequest request = new QueryLoanSignRequest();

		request.setLoanApplicationNo(map.get("appserialno"));
		request.setMemberNo(map.get("memberNo"));
		QueryLoanSignResponse response = loanSignFacade.queryLoanSign(request);
		
		
		//提交签约
		ConfirmLoanSignRequest sigreq = new ConfirmLoanSignRequest();
		sigreq.setLoanSignNo(response.getLoanSignNo());
		sigreq.setSignInfo("{\"fullPath\":\"http://qfdfs.hengdadai.com/group1/M00/00/AA/rBA0HVpgVJiAfssBAAOlPQB76Vg459.png\"}");
		byte status=0;
		if("JSD".equals(map.get("loanType"))){
			status = 20;
		}else{
			status = 4;
		}				
		sigreq.setSignStatus(status);
		sigreq.setSignStatusReason("");
		ConfirmLoanSignResponse sigrsp = loanSignFacade.confirmLoanSign(sigreq);	
		if("1000".equals(sigrsp.getRespCode())){
			System.out.println("线上签约成功....");
			System.out.println("---------------------------------------");
			System.out.println("进件信息： 手机号码：" + map.get("mermberPhone") + "    用户名称:" + map.get("memberName") + "     会员号：" + map.get("memberNo"));
			System.out.println("---------------------------------------");
			logger.error("线上签约成功....");
			logger.error("进件信息： 手机号码：" + map.get("mermberPhone") + "    用户名称:" + map.get("memberName") + "     会员号：" + map.get("memberNo"));
		}else{
			logger.error("签约失败....");
		}
		Assert.assertEquals(sigrsp.getRespCode(), "1000");
		
	}
	
	
	
	
	
	
	public static Date getDate(int d) {
		Date endDate;
		try {
			SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
			Date beginDate = new Date();
			Calendar date = Calendar.getInstance();
			date.setTime(beginDate);
			if (d > 0) {
				date.set(Calendar.DATE, date.get(Calendar.DATE) + d);
			} else {
				date.set(Calendar.DATE, date.get(Calendar.DATE) - Math.abs(d));
			}
			date.set(Calendar.DATE, date.get(Calendar.DATE) - 1);

			endDate = dft.parse(dft.format(date.getTime()));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		return endDate;
	}

//	public String getLoanNo() {
//		return loanNo;
//	}
//
//	public void setLoanNo(String loanNo) {
//		this.loanNo = loanNo;
//	}
//
//	public String getTrackingNo() {
//		return trackingNo;
//	}
//
//	public void setTrackingNo(String trackingNo) {
//		map.get("trackingNo") = trackingNo;
//	}
}
